%% copy riak-0.14.2 source to learn dynamo implementation and erlang
%% author: lichuang
%% copy source from process_proxy.erl

-module(edynamo_process_proxy).
-export([start_link/2, init/1, stop/1]).

start_link(RegName, ProxyTo) ->
  proc_lib:start_link(?MODULE, init, [[self(), RegName, ProxyTo]]).

init([ParentPid, RegName, ProxyTo]) ->
  erlang:register(RegName, self()),
  proc_lib:init_ack(ParentPid, {ok, self()}),
  loop(ProxyTo).

stop(Name) ->
  Name ! stop.

loop(ProxyTo) ->
  receive
    stop ->
      exit(normal);
    M ->
      ProxyTo ! M,
      loop(ProxyTo)
  end.
